/*
// Definition for a Node.
class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
    public List<List<Integer>> levelOrder(Node root) {
        // 返回最终的结果列表
        List<List<Integer>> resList = new ArrayList<>();
        Queue<Node> que = new LinkedList<>();
        que.add(root);
        if (root == null) return resList;
        while (!que.isEmpty()) {
            // 统计队列中当前层所拥有的元素个数
            int levelSize = que.size();
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < levelSize; i++) {
                Node tmp = que.poll();
                for (Node children: tmp.children) {
                    que.add(children);
                }
                list.add(tmp.val);
            }
            resList.add(list);
        }
        return resList;
    }
}
